package com.demo.common;

public class Result {
    private String code;
    private String msg;
    private Object data;
    private ErrorDetail errorDetail;  // 新增错误详情字段

    public static Result success() {
        Result result = new Result();
        result.setCode("200");
        result.setMsg("请求成功");
        return result;
    }

    public static Result success(Object data) {
        Result result = success();
        result.setData(data);
        return result;
    }

    // 新增：使用ErrorDetail创建错误响应
    public static Result error(ErrorDetail detail) {
        Result result = new Result();
        result.setCode(String.valueOf(detail.getHttpCode()));
        result.setMsg(detail.getMessage());
        result.setErrorDetail(detail);
        return result;
    }

    // 保留旧版错误方法（兼容性）
    public static Result error() {
        return error("500", "系统错误");
    }

    public static Result error(String code, String msg) {
        return error(ErrorDetail.builder()
                .httpCode(500)
                .message(msg)
                .build());
    }

    // Getters and Setters
    public String getCode() { return code; }
    public void setCode(String code) { this.code = code; }
    public String getMsg() { return msg; }
    public void setMsg(String msg) { this.msg = msg; }
    public Object getData() { return data; }
    public void setData(Object data) { this.data = data; }
    public ErrorDetail getErrorDetail() { return errorDetail; }
    public void setErrorDetail(ErrorDetail errorDetail) { this.errorDetail = errorDetail; }
}